package com.share.config.configurer;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 支持 字段 和 文件上传和下载 拦截器  springboot挂载目录实现文件下载
 */
@Data
@Component
public class UpLoadFileConfigurer implements WebMvcConfigurer {
    @Value("${file.contextPath")
    private String contextPath;

    @Value("${file.filePath")
    private String filePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(contextPath).addResourceLocations("file:" + filePath);
    }
}
